<?php

/**
 * Spectacle filter form base class.
 *
 * @package    tfe
 * @subpackage filter
 * @author     3emeIG
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseSpectacleFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'titre'                 => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'auteur'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'lieu'                  => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Lieu'), 'add_empty' => true)),
      'date_de_debut'         => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'date_de_fin'           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'heure_de_debut'        => new sfWidgetFormFilterInput(),
      'duree'                 => new sfWidgetFormFilterInput(),
      'type_de_public'        => new sfWidgetFormChoice(array('choices' => array('' => '', 'enfants' => 'enfants', 'ados' => 'ados', 'adultes' => 'adultes', 'ados-adultes' => 'ados-adultes', 'tous publics' => 'tous publics'))),
      'age_mini'              => new sfWidgetFormFilterInput(),
      'commentaire'           => new sfWidgetFormFilterInput(),
      'type'                  => new sfWidgetFormFilterInput(),
      'deleted_at'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'created_at'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'abonnements_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Abonnement')),
      'metteur_en_scene_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Artiste')),
      'acteurs_list'          => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Artiste')),
      'intervenants_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Artiste')),
    ));

    $this->setValidators(array(
      'titre'                 => new sfValidatorPass(array('required' => false)),
      'auteur'                => new sfValidatorPass(array('required' => false)),
      'lieu'                  => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Lieu'), 'column' => 'id')),
      'date_de_debut'         => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'date_de_fin'           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'heure_de_debut'        => new sfValidatorPass(array('required' => false)),
      'duree'                 => new sfValidatorPass(array('required' => false)),
      'type_de_public'        => new sfValidatorChoice(array('required' => false, 'choices' => array('enfants' => 'enfants', 'ados' => 'ados', 'adultes' => 'adultes', 'ados-adultes' => 'ados-adultes', 'tous publics' => 'tous publics'))),
      'age_mini'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'commentaire'           => new sfValidatorPass(array('required' => false)),
      'type'                  => new sfValidatorPass(array('required' => false)),
      'deleted_at'            => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'created_at'            => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'            => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'abonnements_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Abonnement', 'required' => false)),
      'metteur_en_scene_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Artiste', 'required' => false)),
      'acteurs_list'          => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Artiste', 'required' => false)),
      'intervenants_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Artiste', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('spectacle_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addAbonnementsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.ListeSpectacles ListeSpectacles')
          ->andWhereIn('ListeSpectacles.id_abonnement', $values);
  }

  public function addMetteurEnSceneListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.MetteurEnSceneSpectacle MetteurEnSceneSpectacle')
          ->andWhereIn('MetteurEnSceneSpectacle.id_metteur_en_scene', $values);
  }

  public function addActeursListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.ActeurSpectacle ActeurSpectacle')
          ->andWhereIn('ActeurSpectacle.id_acteur', $values);
  }

  public function addIntervenantsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.IntervenantSpectacle IntervenantSpectacle')
          ->andWhereIn('IntervenantSpectacle.id_intervenant', $values);
  }

  public function getModelName()
  {
    return 'Spectacle';
  }

  public function getFields()
  {
    return array(
      'id'                    => 'Number',
      'titre'                 => 'Text',
      'auteur'                => 'Text',
      'lieu'                  => 'ForeignKey',
      'date_de_debut'         => 'Date',
      'date_de_fin'           => 'Date',
      'heure_de_debut'        => 'Text',
      'duree'                 => 'Text',
      'type_de_public'        => 'Enum',
      'age_mini'              => 'Number',
      'commentaire'           => 'Text',
      'type'                  => 'Text',
      'deleted_at'            => 'Date',
      'created_at'            => 'Date',
      'updated_at'            => 'Date',
      'abonnements_list'      => 'ManyKey',
      'metteur_en_scene_list' => 'ManyKey',
      'acteurs_list'          => 'ManyKey',
      'intervenants_list'     => 'ManyKey',
    );
  }
}
